package com.sxz.sbs.module.client;

import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import com.sxz.sbs.R;
import com.sxz.sbs.base.BaseActivity;
import com.sxz.sbs.http.retrofit.HttpParamMap;
import com.sxz.sbs.module.client.presenter.AddPlanPresenter;
import com.sxz.sbs.module.client.view.AddplanView;
import com.sxz.sbs.widget.CommonStar;
import com.sxz.sbs.widget.CommonTitle;
import com.willy.ratingbar.BaseRatingBar;
import com.willy.ratingbar.ScaleRatingBar;

import java.util.HashMap;

import butterknife.BindView;
import butterknife.OnClick;
/**
 * @author hp
 * @date 2018/1/11
 * 客户评价
 */

public class ClientEvaluateActivity extends BaseActivity<AddPlanPresenter> implements AddplanView{

    @BindView(R.id.et_clientevaluate)
    EditText mEditText;
    @BindView(R.id.tv_title_right)
    TextView tvTitleRight;
    @BindView(R.id.client_text)
    TextView clientText;
    @BindView(R.id.client_ratingbar)
    ScaleRatingBar clientRatingBar;
    @BindView(R.id.tv_input_count)
    TextView tv_input_count;
    private CommonStar commonStar=new CommonStar();
    private float starNum = 0;
    private String edst="";

    @Override
    protected void init() {
        new CommonTitle.Builder(this).setTitle("跟进记录").showMore(false).showRightText(true).build().show();
        starNum = Integer.valueOf(getIntent().getStringExtra("starnum"));
        commonStar.initStar(Integer.valueOf(getIntent().getStringExtra("starnum")),clientText);
        clientRatingBar.setNumStars(5);
        clientRatingBar.setRating(Integer.valueOf(getIntent().getStringExtra("starnum")));
        clientRatingBar.setOnRatingChangeListener(new BaseRatingBar.OnRatingChangeListener() {
            @Override
            public void onRatingChange(BaseRatingBar ratingBar, float rating) {
                starNum=rating;
                commonStar.initStar((int)rating,clientText);
            }
        });
        mEditText.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {

            }

            @Override
            public void afterTextChanged(Editable s) {
                tv_input_count.setText(s.toString().length()+"/200");
            }
        });

    }

    @Override
    protected int getLayoutId() {
        return R.layout.activity_clientevaluate;
    }

    @Override
    protected AddPlanPresenter createPresenter() {
        return new AddPlanPresenter();
    }


    @OnClick({R.id.tv_title_right})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.tv_title_right:
                getData();
                break;
            default:
                break;
        }
    }

    @Override
    public void onAddPlanSuccess(String data) {
        finish();
    }

    /**
     * 新增客户进度请求
     */
    private void getData(){
        /**
         customId	int	是	客户Id
         startLevel	int	是	星级
         txtContent	string	是	跟进内容
         */
        HashMap<String, Object> map = HttpParamMap.getParamMap();
        map.put("customId", getIntent().getIntExtra("clientid",0));
        map.put("startLevel", (int)starNum);
        map.put("txtContent", mEditText.getText().toString());
        mPresenter.getAddPlan(map);
    }
}
